home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / VCSN4L (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  14.7 KB  |  791 lines

  1. package com.sun.java.swing.tree;
  2.  
  3. import com.sun.java.swing.DefaultListSelectionModel;
  4. import com.sun.java.swing.event.EventListenerList;
  5. import com.sun.java.swing.event.TreeSelectionEvent;
  6. import com.sun.java.swing.event.TreeSelectionListener;
  7. import java.beans.PropertyChangeListener;
  8. import java.beans.PropertyChangeSupport;
  9. import java.io.IOException;
  10. import java.io.ObjectInputStream;
  11. import java.io.ObjectOutputStream;
  12. import java.io.Serializable;
  13. import java.util.BitSet;
  14. import java.util.Vector;
  15.  
  16. public class DefaultTreeSelectionModel implements Cloneable, Serializable, TreeSelectionModel {
  17.    public static final String SELECTION_MODE_PROPERTY = "selectionMode";
  18.    protected PropertyChangeSupport changeSupport;
  19.    protected TreePath[] selection;
  20.    protected EventListenerList listenerList = new EventListenerList();
  21.    protected transient RowMapper rowMapper;
  22.    protected DefaultListSelectionModel listSelectionModel = new DefaultListSelectionModel();
  23.    protected int selectionMode = 4;
  24.    protected TreePath leadPath;
  25.    protected int leadIndex;
  26.    protected int leadRow;
  27.    static Class class$com$sun$java$swing$event$TreeSelectionListener;
  28.  
  29.    public DefaultTreeSelectionModel() {
  30.       this.leadIndex = this.leadRow = -1;
  31.    }
  32.  
  33.    public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
  34.       if (this.changeSupport == null) {
  35.          this.changeSupport = new PropertyChangeSupport(this);
  36.       }
  37.  
  38.       this.changeSupport.addPropertyChangeListener(listener);
  39.    }
  40.  
  41.    public void addSelectionPath(TreePath path) {
  42.       if (path != null) {
  43.          TreePath[] toAdd = new TreePath[1];
  44.          toAdd[0] = path;
  45.          this.addSelectionPaths(toAdd);
  46.       }
  47.  
  48.    }
  49.  
  50.    public void addSelectionPaths(TreePath[] paths) {
  51.       int newPathLength = paths == null ? 0 : paths.length;
  52.       if (newPathLength > 0) {
  53.          if (this.selectionMode == 1 && this.selection != null && this.selection.length > 0) {
  54.             this.setSelectionPaths(paths);
  55.          } else if (this.selectionMode == 2 && !this.canPathsBeAdded(paths)) {
  56.             if (this.arePathsContiguous(paths)) {
  57.                this.setSelectionPaths(paths);
  58.             } else {
  59.                TreePath[] newPaths = new TreePath[1];
  60.                newPaths[0] = paths[0];
  61.                this.setSelectionPaths(newPaths);
  62.             }
  63.          } else {
  64.             TreePath beginLeadPath = this.leadPath;
  65.             Vector cPaths = null;
  66.             int oldCount;
  67.             if (this.selection == null) {
  68.                oldCount = 0;
  69.             } else {
  70.                oldCount = this.selection.length;
  71.             }
  72.  
  73.             boolean newPaths = false;
  74.             this.leadPath = null;
  75.             int counter = 0;
  76.  
  77.             int validCount;
  78.             for(validCount = 0; counter < paths.length; ++counter) {
  79.                if (paths[counter] != null) {
  80.                   boolean inSelection = false;
  81.  
  82.                   for(int oldCounter = 0; oldCounter < oldCount; ++oldCounter) {
  83.                      if (paths[counter].equals(this.selection[oldCounter])) {
  84.                         oldCounter = oldCount;
  85.                         if (!newPaths) {
  86.                            TreePath[] copiedPaths = new TreePath[paths.length];
  87.                            System.arraycopy(paths, 0, copiedPaths, 0, paths.length);
  88.                            paths = copiedPaths;
  89.                            newPaths = true;
  90.                         }
  91.  
  92.                         paths[counter] = null;
  93.                         inSelection = true;
  94.                      }
  95.                   }
  96.  
  97.                   if (!inSelection) {
  98.                      ++validCount;
  99.                      if (cPaths == null) {
  100.                         cPaths = new Vector();
  101.                      }
  102.  
  103.                      cPaths.addElement(new PathPlaceHolder(paths[counter], true));
  104.                   }
  105.  
  106.                   if (this.leadPath == null) {
  107.                      this.leadPath = paths[counter];
  108.                   }
  109.                }
  110.             }
  111.  
  112.             if (this.leadPath == null) {
  113.                this.leadPath = beginLeadPath;
  114.             }
  115.  
  116.             if (validCount > 0) {
  117.                TreePath[] newSelection = new TreePath[oldCount + validCount];
  118.                if (oldCount > 0) {
  119.                   System.arraycopy(this.selection, 0, newSelection, 0, oldCount);
  120.                }
  121.  
  122.                if (validCount != paths.length) {
  123.                   int validCounter = 0;
  124.  
  125.                   for(int var14 = 0; var14 < paths.length; ++var14) {
  126.                      if (paths[var14] != null) {
  127.                         newSelection[oldCount + validCounter++] = paths[var14];
  128.                      }
  129.                   }
  130.                } else {
  131.                   System.arraycopy(paths, 0, newSelection, oldCount, validCount);
  132.                }
  133.  
  134.                this.selection = newSelection;
  135.                this.insureUniqueness();
  136.                this.updateLeadIndex();
  137.                this.resetRowSelection();
  138.                this.notifyPathChange(cPaths, beginLeadPath);
  139.             } else {
  140.                this.leadPath = beginLeadPath;
  141.             }
  142.          }
  143.       }
  144.  
  145.    }
  146.  
  147.    public void addTreeSelectionListener(TreeSelectionListener x) {
  148.       EventListenerList var10000 = this.listenerList;
  149.       Class var10001 = class$com$sun$java$swing$event$TreeSelectionListener;
  150.       if (var10001 == null) {
  151.          try {
  152.             var10001 = Class.forName("com.sun.java.swing.event.TreeSelectionListener");
  153.          } catch (ClassNotFoundException var2) {
  154.             throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  155.          }
  156.  
  157.          class$com$sun$java$swing$event$TreeSelectionListener = var10001;
  158.       }
  159.  
  160.       var10000.add(var10001, x);
  161.    }
  162.  
  163.    protected boolean arePathsContiguous(TreePath[] paths) {
  164.       if (this.rowMapper != null && paths.length >= 2) {
  165.          BitSet bitSet = new BitSet(32);
  166.          int pathCount = paths.length;
  167.          int validCount = 0;
  168.          TreePath[] tempPath = new TreePath[]{paths[0]};
  169.          int min = this.rowMapper.getRowsForPaths(tempPath)[0];
  170.  
  171.          for(int counter = 0; counter < pathCount; ++counter) {
  172.             if (paths[counter] != null) {
  173.                tempPath[0] = paths[counter];
  174.                int anIndex = this.rowMapper.getRowsForPaths(tempPath)[0];
  175.                if (anIndex == -1 || anIndex < min - pathCount || anIndex > min + pathCount) {
  176.                   return false;
  177.                }
  178.  
  179.                if (anIndex < min) {
  180.                   min = anIndex;
  181.                }
  182.  
  183.                if (!bitSet.get(anIndex)) {
  184.                   bitSet.set(anIndex);
  185.                   ++validCount;
  186.                }
  187.             }
  188.          }
  189.  
  190.          int maxCounter = validCount + min;
  191.  
  192.          for(int var10 = min; var10 < maxCounter; ++var10) {
  193.             if (!bitSet.get(var10)) {
  194.                return false;
  195.             }
  196.          }
  197.  
  198.          return true;
  199.       } else {
  200.          return true;
  201.       }
  202.    }
  203.  
  204.    protected boolean canPathsBeAdded(TreePath[] paths) {
  205.       if (paths != null && paths.length != 0 && this.rowMapper != null && this.selection != null && this.selectionMode != 4) {
  206.          BitSet bitSet = new BitSet();
  207.          DefaultListSelectionModel lModel = this.listSelectionModel;
  208.          int min = lModel.getMinSelectionIndex();
  209.          int max = lModel.getMaxSelectionIndex();
  210.          TreePath[] tempPath = new TreePath[1];
  211.          if (min != -1) {
  212.             for(int counter = min; counter <= max; ++counter) {
  213.                if (lModel.isSelectedIndex(min)) {
  214.                   bitSet.set(counter);
  215.                }
  216.             }
  217.          } else {
  218.             tempPath[0] = paths[0];
  219.             min = max = this.rowMapper.getRowsForPaths(tempPath)[0];
  220.          }
  221.  
  222.          for(int var9 = paths.length - 1; var9 >= 0; --var9) {
  223.             if (paths[var9] != null) {
  224.                tempPath[0] = paths[var9];
  225.                int anIndex = this.rowMapper.getRowsForPaths(tempPath)[0];
  226.                min = Math.min(anIndex, min);
  227.                max = Math.max(anIndex, max);
  228.                if (anIndex == -1) {
  229.                   return false;
  230.                }
  231.  
  232.                bitSet.set(anIndex);
  233.             }
  234.          }
  235.  
  236.          for(int var10 = min; var10 <= max; ++var10) {
  237.             if (!bitSet.get(var10)) {
  238.                return false;
  239.             }
  240.          }
  241.  
  242.          return true;
  243.       } else {
  244.          return true;
  245.       }
  246.    }
  247.  
  248.    protected boolean canPathsBeRemoved(TreePath[] paths) {
  249.       if (this.rowMapper != null && this.selection != null && this.selectionMode != 4) {
  250.          BitSet bitSet = new BitSet();
  251.          int pathCount = paths.length;
  252.          int min = -1;
  253.          int validCount = 0;
  254.          TreePath[] tPaths = new TreePath[pathCount];
  255.          TreePath[] tempPath = new TreePath[1];
  256.          System.arraycopy(paths, 0, tPaths, 0, pathCount);
  257.  
  258.          for(int counter = this.selection.length - 1; counter >= 0; --counter) {
  259.             boolean found = false;
  260.  
  261.             for(int rCounter = 0; rCounter < pathCount; ++rCounter) {
  262.                if (tPaths[rCounter] != null && this.selection[counter].equals(tPaths[rCounter])) {
  263.                   tPaths[rCounter] = null;
  264.                   found = true;
  265.                   break;
  266.                }
  267.             }
  268.  
  269.             if (!found) {
  270.                tempPath[0] = this.selection[counter];
  271.                int anIndex = this.rowMapper.getRowsForPaths(tempPath)[0];
  272.                if (anIndex != -1 && !bitSet.get(anIndex)) {
  273.                   ++validCount;
  274.                   if (min == -1) {
  275.                      min = anIndex;
  276.                   } else {
  277.                      min = Math.min(min, anIndex);
  278.                   }
  279.  
  280.                   bitSet.set(anIndex);
  281.                }
  282.             }
  283.          }
  284.  
  285.          if (validCount > 1) {
  286.             for(int var12 = min + validCount - 1; var12 >= min; --var12) {
  287.                if (!bitSet.get(var12)) {
  288.                   return false;
  289.                }
  290.             }
  291.          }
  292.  
  293.          return true;
  294.       } else {
  295.          return true;
  296.       }
  297.    }
  298.  
  299.    public void clearSelection() {
  300.       if (this.selection != null) {
  301.          int selSize = this.selection.length;
  302.          boolean[] newness = new boolean[selSize];
  303.  
  304.          for(int counter = 0; counter < selSize; ++counter) {
  305.             newness[counter] = false;
  306.          }
  307.  
  308.          TreeSelectionEvent event = new TreeSelectionEvent(this, this.selection, newness, this.leadPath, (TreePath)null);
  309.          this.leadPath = null;
  310.          this.leadIndex = this.leadRow = -1;
  311.          this.selection = null;
  312.          this.resetRowSelection();
  313.          this.fireValueChanged(event);
  314.       }
  315.  
  316.    }
  317.  
  318.    public Object clone() throws CloneNotSupportedException {
  319.       DefaultTreeSelectionModel clone = (DefaultTreeSelectionModel)super.clone();
  320.       clone.changeSupport = null;
  321.       if (this.selection != null) {
  322.          int selLength = this.selection.length;
  323.          clone.selection = new TreePath[selLength];
  324.          System.arraycopy(this.selection, 0, clone.selection, 0, selLength);
  325.       }
  326.  
  327.       clone.listenerList = new EventListenerList();
  328.       clone.listSelectionModel = (DefaultListSelectionModel)this.listSelectionModel.clone();
  329.       return clone;
  330.    }
  331.  
  332.    protected void fireValueChanged(TreeSelectionEvent e) {
  333.       Object[] listeners = this.listenerList.getListenerList();
  334.  
  335.       for(int i = listeners.length - 2; i >= 0; i -= 2) {
  336.          Object var10000 = listeners[i];
  337.          Class var10001 = class$com$sun$java$swing$event$TreeSelectionListener;
  338.          if (var10001 == null) {
  339.             try {
  340.                var10001 = Class.forName("com.sun.java.swing.event.TreeSelectionListener");
  341.             } catch (ClassNotFoundException var4) {
  342.                throw new NoClassDefFoundError(((Throwable)var4).getMessage());
  343.             }
  344.  
  345.             class$com$sun$java$swing$event$TreeSelectionListener = var10001;
  346.          }
  347.  
  348.          if (var10000 == var10001) {
  349.             ((TreeSelectionListener)listeners[i + 1]).valueChanged(e);
  350.          }
  351.       }
  352.  
  353.    }
  354.  
  355.    public TreePath getLeadSelectionPath() {
  356.       return this.leadPath;
  357.    }
  358.  
  359.    public int getLeadSelectionRow() {
  360.       return this.leadRow;
  361.    }
  362.  
  363.    public int getMaxSelectionRow() {
  364.       return this.listSelectionModel.getMaxSelectionIndex();
  365.    }
  366.  
  367.    public int getMinSelectionRow() {
  368.       return this.listSelectionModel.getMinSelectionIndex();
  369.    }
  370.  
  371.    public RowMapper getRowMapper() {
  372.       return this.rowMapper;
  373.    }
  374.  
  375.    public int getSelectionCount() {
  376.       return this.selection == null ? 0 : this.selection.length;
  377.    }
  378.  
  379.    public int getSelectionMode() {
  380.       return this.selectionMode;
  381.    }
  382.  
  383.    public TreePath getSelectionPath() {
  384.       return this.selection != null ? this.selection[0] : null;
  385.    }
  386.  
  387.    public TreePath[] getSelectionPaths() {
  388.       if (this.selection != null) {
  389.          int pathSize = this.selection.length;
  390.          TreePath[] result = new TreePath[pathSize];
  391.          System.arraycopy(this.selection, 0, result, 0, pathSize);
  392.          return result;
  393.       } else {
  394.          return null;
  395.       }
  396.    }
  397.  
  398.    public int[] getSelectionRows() {
  399.       return this.rowMapper != null && this.selection != null ? this.rowMapper.getRowsForPaths(this.selection) : null;
  400.    }
  401.  
  402.    protected void insureRowContinuity() {
  403.       if (this.selectionMode == 2 && this.selection != null && this.rowMapper != null) {
  404.          DefaultListSelectionModel lModel = this.listSelectionModel;
  405.          int min = lModel.getMinSelectionIndex();
  406.          if (min != -1) {
  407.             int counter = min;
  408.  
  409.             for(int maxCounter = lModel.getMaxSelectionIndex(); counter <= maxCounter; ++counter) {
  410.                if (!lModel.isSelectedIndex(counter)) {
  411.                   if (counter != min) {
  412.                      TreePath[] newSel = new TreePath[counter - min];
  413.                      System.arraycopy(this.selection, 0, newSel, 0, counter - min);
  414.                      this.setSelectionPaths(newSel);
  415.                      break;
  416.                   }
  417.  
  418.                   this.clearSelection();
  419.                }
  420.             }
  421.          }
  422.       } else if (this.selectionMode == 1 && this.selection != null && this.selection.length > 1) {
  423.          this.setSelectionPath(this.selection[0]);
  424.       }
  425.  
  426.    }
  427.  
  428.    protected void insureUniqueness() {
  429.       int dupCount = 0;
  430.  
  431.       for(int compareCounter = 0; compareCounter < this.selection.length; ++compareCounter) {
  432.          if (this.selection[compareCounter] != null) {
  433.             for(int indexCounter = compareCounter + 1; indexCounter < this.selection.length; ++indexCounter) {
  434.                if (this.selection[indexCounter] != null && this.selection[compareCounter].equals(this.selection[indexCounter])) {
  435.                   ++dupCount;
  436.                   this.selection[indexCounter] = null;
  437.                }
  438.             }
  439.          }
  440.       }
  441.  
  442.       if (dupCount > 0) {
  443.          TreePath[] newSelection = new TreePath[this.selection.length - dupCount];
  444.          int counter = 0;
  445.  
  446.          for(int validCounter = 0; counter < this.selection.length; ++counter) {
  447.             if (this.selection[counter] != null) {
  448.                newSelection[validCounter++] = this.selection[counter];
  449.             }
  450.          }
  451.  
  452.          this.selection = newSelection;
  453.       }
  454.  
  455.    }
  456.  
  457.    public boolean isPathSelected(TreePath path) {
  458.       if (this.selection != null) {
  459.          for(int counter = 0; counter < this.selection.length; ++counter) {
  460.             if (this.selection[counter].equals(path)) {
  461.                return true;
  462.             }
  463.          }
  464.       }
  465.  
  466.       return false;
  467.    }
  468.  
  469.    public boolean isRowSelected(int row) {
  470.       return this.listSelectionModel.isSelectedIndex(row);
  471.    }
  472.  
  473.    public boolean isSelectionEmpty() {
  474.       return this.selection == null;
  475.    }
  476.  
  477.    protected void notifyPathChange(Vector changedPaths, TreePath oldLeadSelection) {
  478.       int cPathCount = changedPaths.size();
  479.       boolean[] newness = new boolean[cPathCount];
  480.       TreePath[] paths = new TreePath[cPathCount];
  481.  
  482.       for(int counter = 0; counter < cPathCount; ++counter) {
  483.          PathPlaceHolder placeholder = (PathPlaceHolder)changedPaths.elementAt(counter);
  484.          newness[counter] = placeholder.isNew;
  485.          paths[counter] = placeholder.path;
  486.       }
  487.  
  488.       TreeSelectionEvent event = new TreeSelectionEvent(this, paths, newness, oldLeadSelection, this.leadPath);
  489.       this.fireValueChanged(event);
  490.    }
  491.  
  492.    private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
  493.       s.defaultReadObject();
  494.       Object[] tValues = s.readObject();
  495.       if (tValues.length > 0 && tValues[0].equals("rowMapper")) {
  496.          this.rowMapper = (RowMapper)tValues[1];
  497.       }
  498.  
  499.    }
  500.  
  501.    public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
  502.       if (this.changeSupport != null) {
  503.          this.changeSupport.removePropertyChangeListener(listener);
  504.       }
  505.    }
  506.  
  507.    public void removeSelectionPath(TreePath path) {
  508.       if (path != null) {
  509.          TreePath[] rPath = new TreePath[1];
  510.          rPath[0] = path;
  511.          this.removeSelectionPaths(rPath);
  512.       }
  513.  
  514.    }
  515.  
  516.    public void removeSelectionPaths(TreePath[] paths) {
  517.       if (paths != null && this.selection != null && paths.length > 0) {
  518.          if (!this.canPathsBeRemoved(paths)) {
  519.             this.clearSelection();
  520.          } else {
  521.             TreePath beginLeadPath = this.leadPath;
  522.             Vector pathsToRemove = null;
  523.             int oldCount = this.selection.length;
  524.  
  525.             for(int removeCounter = 0; removeCounter < paths.length; ++removeCounter) {
  526.                if (paths[removeCounter] != null) {
  527.                   if (this.leadPath != null && this.leadPath.equals(paths[removeCounter])) {
  528.                      this.leadPath = null;
  529.                   }
  530.  
  531.                   for(int oldCounter = 0; oldCounter < oldCount; ++oldCounter) {
  532.                      if (paths[removeCounter].equals(this.selection[oldCounter])) {
  533.                         this.selection[oldCounter] = null;
  534.                         oldCounter = oldCount;
  535.                         if (pathsToRemove == null) {
  536.                            pathsToRemove = new Vector(paths.length);
  537.                         }
  538.  
  539.                         if (!pathsToRemove.contains(paths[removeCounter])) {
  540.                            pathsToRemove.addElement(new PathPlaceHolder(paths[removeCounter], false));
  541.                         }
  542.                      }
  543.                   }
  544.                }
  545.             }
  546.  
  547.             if (pathsToRemove != null) {
  548.                int removeCount = pathsToRemove.size();
  549.                if (removeCount == this.selection.length) {
  550.                   this.selection = null;
  551.                } else {
  552.                   int validCount = 0;
  553.                   TreePath[] newSelection = new TreePath[this.selection.length - removeCount];
  554.  
  555.                   for(int var10 = 0; var10 < oldCount; ++var10) {
  556.                      if (this.selection[var10] != null) {
  557.                         newSelection[validCount++] = this.selection[var10];
  558.                      }
  559.                   }
  560.  
  561.                   this.selection = newSelection;
  562.                }
  563.  
  564.                if (this.leadPath == null && this.selection != null) {
  565.                   this.leadPath = this.selection[0];
  566.                }
  567.  
  568.                this.updateLeadIndex();
  569.                this.resetRowSelection();
  570.                this.notifyPathChange(pathsToRemove, beginLeadPath);
  571.             }
  572.          }
  573.       }
  574.  
  575.    }
  576.  
  577.    public void removeTreeSelectionListener(TreeSelectionListener x) {
  578.       EventListenerList var10000 = this.listenerList;
  579.       Class var10001 = class$com$sun$java$swing$event$TreeSelectionListener;
  580.       if (var10001 == null) {
  581.          try {
  582.             var10001 = Class.forName("com.sun.java.swing.event.TreeSelectionListener");
  583.          } catch (ClassNotFoundException var2) {
  584.             throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  585.          }
  586.  
  587.          class$com$sun$java$swing$event$TreeSelectionListener = var10001;
  588.       }
  589.  
  590.       var10000.remove(var10001, x);
  591.    }
  592.  
  593.    public void resetRowSelection() {
  594.       this.listSelectionModel.clearSelection();
  595.       if (this.selection != null && this.rowMapper != null) {
  596.          int[] rows = this.rowMapper.getRowsForPaths(this.selection);
  597.          int counter = 0;
  598.  
  599.          for(int maxCounter = this.selection.length; counter < maxCounter; ++counter) {
  600.             int aRow = rows[counter];
  601.             if (aRow != -1) {
  602.                this.listSelectionModel.addSelectionInterval(aRow, aRow);
  603.             }
  604.          }
  605.  
  606.          if (this.leadIndex != -1) {
  607.             this.leadRow = rows[this.leadIndex];
  608.          }
  609.  
  610.          this.insureRowContinuity();
  611.       } else {
  612.          this.leadRow = -1;
  613.       }
  614.  
  615.    }
  616.  
  617.    public void setRowMapper(RowMapper newMapper) {
  618.       this.rowMapper = newMapper;
  619.       this.resetRowSelection();
  620.    }
  621.  
  622.    public void setSelectionMode(int mode) {
  623.       int oldMode = this.selectionMode;
  624.       this.selectionMode = mode;
  625.       if (this.selectionMode != 1 && this.selectionMode != 2 && this.selectionMode != 4) {
  626.          this.selectionMode = 4;
  627.       }
  628.  
  629.       if (oldMode != this.selectionMode && this.changeSupport != null) {
  630.          this.changeSupport.firePropertyChange("selectionMode", new Integer(oldMode), new Integer(this.selectionMode));
  631.       }
  632.  
  633.    }
  634.  
  635.    public void setSelectionPath(TreePath path) {
  636.       if (path == null) {
  637.          this.setSelectionPaths((TreePath[])null);
  638.       } else {
  639.          TreePath[] newPaths = new TreePath[1];
  640.          newPaths[0] = path;
  641.          this.setSelectionPaths(newPaths);
  642.       }
  643.  
  644.    }
  645.  
  646.    public void setSelectionPaths(TreePath[] pPaths) {
  647.       TreePath[] paths = pPaths;
  648.       int newCount;
  649.       if (pPaths == null) {
  650.          newCount = 0;
  651.       } else {
  652.          newCount = pPaths.length;
  653.       }
  654.  
  655.       int oldCount;
  656.       if (this.selection == null) {
  657.          oldCount = 0;
  658.       } else {
  659.          oldCount = this.selection.length;
  660.       }
  661.  
  662.       if (newCount + oldCount != 0) {
  663.          if (this.selectionMode == 1) {
  664.             if (newCount > 1) {
  665.                paths = new TreePath[]{pPaths[0]};
  666.                newCount = 1;
  667.             }
  668.          } else if (this.selectionMode == 2 && newCount > 0 && !this.arePathsContiguous(pPaths)) {
  669.             paths = new TreePath[]{pPaths[0]};
  670.             newCount = 1;
  671.          }
  672.  
  673.          int validCount = 0;
  674.          TreePath beginLeadPath = this.leadPath;
  675.          Vector cPaths = new Vector(newCount + oldCount);
  676.          this.leadPath = null;
  677.  
  678.          for(int newCounter = 0; newCounter < newCount; ++newCounter) {
  679.             boolean found = false;
  680.             if (paths[newCounter] != null) {
  681.                ++validCount;
  682.  
  683.                for(int oldCounter = 0; oldCounter < oldCount; ++oldCounter) {
  684.                   if (this.selection[oldCounter] != null && this.selection[oldCounter].equals(paths[newCounter])) {
  685.                      this.selection[oldCounter] = null;
  686.                      oldCounter = oldCount;
  687.                      found = true;
  688.                   }
  689.                }
  690.  
  691.                if (!found) {
  692.                   cPaths.addElement(new PathPlaceHolder(paths[newCounter], true));
  693.                }
  694.  
  695.                if (this.leadPath == null) {
  696.                   this.leadPath = paths[newCounter];
  697.                }
  698.             }
  699.          }
  700.  
  701.          for(int var12 = 0; var12 < oldCount; ++var12) {
  702.             if (this.selection[var12] != null) {
  703.                cPaths.addElement(new PathPlaceHolder(this.selection[var12], false));
  704.             }
  705.          }
  706.  
  707.          if (validCount == 0) {
  708.             this.selection = null;
  709.          } else if (validCount != newCount) {
  710.             this.selection = new TreePath[validCount];
  711.             int var11 = 0;
  712.  
  713.             for(int var13 = 0; var11 < newCount; ++var11) {
  714.                if (paths[var11] != null) {
  715.                   this.selection[var13++] = paths[var11];
  716.                }
  717.             }
  718.          } else {
  719.             this.selection = new TreePath[paths.length];
  720.             System.arraycopy(paths, 0, this.selection, 0, paths.length);
  721.          }
  722.  
  723.          if (this.selection != null) {
  724.             this.insureUniqueness();
  725.          }
  726.  
  727.          this.updateLeadIndex();
  728.          this.resetRowSelection();
  729.          if (cPaths.size() > 0) {
  730.             this.notifyPathChange(cPaths, beginLeadPath);
  731.          }
  732.       }
  733.  
  734.    }
  735.  
  736.    public String toString() {
  737.       int selCount = this.getSelectionCount();
  738.       StringBuffer retBuffer = new StringBuffer();
  739.       int[] rows;
  740.       if (this.rowMapper != null) {
  741.          rows = this.rowMapper.getRowsForPaths(this.selection);
  742.       } else {
  743.          rows = null;
  744.       }
  745.  
  746.       retBuffer.append(this.getClass().getName() + " " + this.hashCode() + " [ ");
  747.  
  748.       for(int counter = 0; counter < selCount; ++counter) {
  749.          if (rows != null) {
  750.             retBuffer.append(this.selection[counter].toString() + "@" + Integer.toString(rows[counter]) + " ");
  751.          } else {
  752.             retBuffer.append(this.selection[counter].toString() + " ");
  753.          }
  754.       }
  755.  
  756.       retBuffer.append("]");
  757.       return retBuffer.toString();
  758.    }
  759.  
  760.    protected void updateLeadIndex() {
  761.       if (this.leadPath != null) {
  762.          if (this.selection == null) {
  763.             this.leadPath = null;
  764.             this.leadIndex = this.leadRow = -1;
  765.          } else {
  766.             this.leadRow = this.leadIndex = -1;
  767.  
  768.             for(int counter = this.selection.length - 1; counter >= 0; --counter) {
  769.                if (this.selection[counter].equals(this.leadPath)) {
  770.                   this.leadIndex = counter;
  771.                   break;
  772.                }
  773.             }
  774.          }
  775.       }
  776.  
  777.    }
  778.  
  779.    private void writeObject(ObjectOutputStream s) throws IOException {
  780.       s.defaultWriteObject();
  781.       Object[] tValues;
  782.       if (this.rowMapper != null && this.rowMapper instanceof Serializable) {
  783.          tValues = new Object[]{"rowMapper", this.rowMapper};
  784.       } else {
  785.          tValues = new Object[0];
  786.       }
  787.  
  788.       s.writeObject(tValues);
  789.    }
  790. }
  791.